package com.huawei.spare.part.replace.expectit;

import static net.sf.expectit.matcher.Matchers.contains;
import static net.sf.expectit.matcher.Matchers.regexp;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import net.sf.expectit.Expect;
import net.sf.expectit.ExpectBuilder;

/**
 * An example of using a lambda as a matcher.
 */
public class Java8Example {
  public static void main(String[] args) throws IOException {
    try (final Expect expect = new ExpectBuilder()
        .withInputs(System.in)
        .withOutput(System.out)
        .build()) {
/*            Result result = expect.expect((input, isEof) -> isEof
                    ? success(input, input, "")
                    : failure(input, false));
            System.out.println(result.getBefore());*/

      expect.interact()
          .when(contains("abc")).then(r -> System.out.println("A"))
          .when(contains("xyz")).then(r -> System.err.println("B"))
          .when(contains("def")).then((r) -> {
        expect.sendLine("hello");
        expect.interact()
            .when(contains("rbc")).then(r2 -> System.err.println("C"))
            .until(contains("klm"));

      })
          .until(contains("exit"));
      System.out.println("DONE!");
    }
    System.in.close();
  }
}